/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Beans;

import Entities.TblCurriculum;
import Entities.TblSemester;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.event.ValueChangeEvent;

/**
 *
 * @author CuongNV
 */
@ManagedBean
@RequestScoped
public class SemesterManagedBean extends TblSemester {

    /** Creates a new instance of SemesterManagedBean */
    public SemesterManagedBean() {
    }
    private List<TblSemester> all;
    private SemesterManagedBean semesterBean;
    public List<TblSemester> selectedSemester;
    public String curId;

    public String add() {
        try {
            new BLL.SemesterBLL().add(this.semesterBean);
            return "semesterlist";
        } catch (Exception ex) {
            Logger.getLogger(BranchManagedBean.class.getName()).log(Level.SEVERE, null, ex);
            return "null";
        }
    }

    public String update() {
        if (new BLL.SemesterBLL().update(this.semesterBean)) {
            return "semesterlist";
        } else {
            return "null";
        }
    }

    public String delete() {
        if (new BLL.SemesterBLL().delete(this.semesterBean)) {
            return "semesterlist";
        } else {
            return "null";
        }
    }

    public List<TblSemester> getAll() {
        return new BLL.SemesterBLL().getAll();
    }

    public String curriculumNameById(int curriculumId){
        TblCurriculum objCurri=new BLL.CurriculumBLL().getById(curriculumId);
        return objCurri.getCurriculumName();
    }
    public String getCurId() {
        return curId;
    }

    public void setCurId(String curId) {
        this.curId = curId;
    }

    public void setSelectedSemester(List<TblSemester> selectedSemester) {
        this.selectedSemester = selectedSemester;
    }

    public List<TblSemester> getSelectedSemester() {
        return selectedSemester;
    }

    public void laySem(ValueChangeEvent e) {
        //assign new value to localeCode
        curId = e.getNewValue().toString();
        selectedSemester = getSemesterByCurriculumId(Integer.parseInt(curId));
    }

    public List<TblSemester> getSemesterByCurriculumId(int curriculumId) {
        return new BLL.SemesterBLL().getSemesterByCurriculumId(curriculumId);
    }

    public SemesterManagedBean getSemesterBean() {
        return semesterBean;
    }

    public void setSemesterBean(SemesterManagedBean semesterBean) {
        this.semesterBean = semesterBean;
    }
}
